home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / Apple Game Sprockets / Examples / InputSprocketPPTest / ISpPPTestTools.cp < prev    next >
Encoding:
Text File  |  1996-05-16  |  1.1 KB  |  63 lines  |  [TEXT/CWIE]

  1. #include "ISpPPTestTools.h"
  2.  
  3. void UInt32ToHexBytes(UInt32 number, unsigned char *bytes)
  4. {    
  5.     UInt32 mask = 0xf0000000;
  6.     int itr;
  7.     
  8.  
  9.     for(itr = 0; itr < 8; itr++)
  10.     {
  11.         UInt32 digit = number & mask;
  12.         digit = digit >> (4 * (7 - itr));
  13.         
  14.         char theChar;
  15.  
  16.         if ((digit >= 0) && (digit <= 9))
  17.         {
  18.             theChar = '0' + digit;
  19.         }
  20.         else if ((digit >= 10) && (digit <= 15))
  21.         {
  22.             theChar = 'a' + digit - 10;
  23.         }
  24.         else
  25.         {
  26.             theChar ='?';
  27.         }
  28.         
  29.         *bytes = theChar;
  30.         bytes++;
  31.         
  32.         mask = mask >> 4;
  33.     }
  34. }
  35.  
  36. void UInt32ToHexString(UInt32 number, Str255 theString)
  37. {
  38.     theString[0] = 10;
  39.     theString[1] = '0';
  40.     theString[2] = 'x';
  41.     
  42.     UInt32ToHexBytes(number, &(theString[3]));
  43. }
  44.  
  45. void UnsignedWideToHexString(const UnsignedWide &number, Str255 theString)
  46. {
  47.     theString[0] = 18;
  48.     theString[1] = '0';
  49.     theString[2] = 'x';
  50.  
  51.     UInt32ToHexBytes(number.hi, &(theString[3]));
  52.     UInt32ToHexBytes(number.lo, &(theString[11]));
  53. }
  54.  
  55. void UInt32ToFourByte(UInt32 number, Str255 theString)
  56. {
  57.     theString[0] = 4;
  58.     theString[1] = (number & 0xff000000) >> 24;
  59.     theString[2] = (number & 0x00ff0000) >> 16;
  60.     theString[3] = (number & 0x0000ff00) >> 8;
  61.     theString[4] = (number & 0x000000ff) >> 0;
  62. }
  63.